package com.roy.eureka.client.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheRemove;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheResult;
import com.roy.eureka.api.dto.User;

@Service
public class HystrixCacheService {

	Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@CacheResult
	@HystrixCommand(commandKey="cacheKey")
	public User cacheUser(String userId) {
		logger.info("========cache user==========");
		User res = new User();
		res.setUserId(userId);
		res.setUserName("set from cacheUser");
		return res;
	}
	
	@CacheResult
	@HystrixCommand(commandKey = "cacheKey")
	public User getCache(String userId) {
		logger.info("========get cache user==========");
		User res = new User();
		res.setUserId(userId);
		res.setUserName("set from cacheUser");
		return res;
	}
	
	@CacheRemove(commandKey = "cacheKey")
	@HystrixCommand
	public void removeCache(String Id) {
		logger.info("=======remove cache======");
	}
}
